﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdvanceLib.ScriptCore;

namespace AdvanceLib
{
    public class Script
    {
        #region Constructors
        public Script()
        {
            this.Data = new Dictionary<long, byte[]>();
            this.Sections = new List<ScriptSection>();
        }
        public Script(List<ScriptSection> sections) : this()
        {
            this.Sections = sections;
        }
        #endregion

        #region Properties
        public static Script Empty
        {
            get { return new Script(); }
        }

        public Dictionary<long, byte[]> Data { get; set; }
        public List<ScriptSection> Sections { get; set; }
        #endregion

        #region Methods
        public Script Compile()
        {
            foreach (ScriptSection section in this.Sections)
            {
                List<byte> sectionData = new List<byte>();

                foreach (ICommand command in section.Commands)
                    sectionData.AddRange(command.GetHexCode());

                this.Data.Add(section.Offset, sectionData.ToArray());
            }
            return this;
        }
        #endregion
    }
}
